import { defineComponent, ref } from 'vue'
import {
  NButton,
  NDataTable,
  NIcon,
  NInput,
  NPagination,
  NSpace,
  NSelect
} from 'naive-ui'
import { SearchOutlined } from '@vicons/antd'
import Card from '@/components/card'
import { useColumns } from './use-columns'
import { useTable } from './use-table'
import { useI18n } from 'vue-i18n'

export default  defineComponent({
  name: 'WorkPublishListTab',
  setup() {
    console.log('WorkPublishListTab')
    const showCreateProjectModalRef = ref(false)
    const { state, updateList, changePage, changePageSize, onOperationClick } =
      useTable()
    const { columnsRef } = useColumns(onOperationClick)

    const taskTypes =  [
      {
        label: "SHELL",
        value: 'SHELL',
      },
      {
        label: "DATAX",
        value: 'DATAX',
      },
      {
        label: "SQL",
        value: 'SQL',
      }
    ] 

    return {
      taskTypes,
      state,
      columnsRef,
      onUpdatedList: updateList,
      changePage,
      changePageSize,
      showCreateProjectModalRef
    }
  },
  methods: {
    onCreateProject() {
      this.showCreateProjectModalRef = true
    },
  },
  render() {
    const { t } = useI18n()
    return (
      <>
        <NSpace vertical>
          <Card>
            <NSpace justify='space-between'>
              <NSpace>
                <NInput
                  v-model:value={this.state.searchParam.name}
                  clearable
                  size='small'
                  placeholder={t('project.workpublish.workNameTips')}
                  style='width: 140px'
                />
                <NSelect
                  v-model:value={this.state.searchParam.taskType}
                  options={this.taskTypes}
                  clearable
                  size='small'
                  placeholder={ t('project.workpublish.workTypeNameTips')}
                  style='width: 180px'
                />
                <NButton type='info' size='small' onClick={this.onUpdatedList}>
                  <NIcon>
                    <SearchOutlined />
                  </NIcon>
                </NButton>
              </NSpace>
            </NSpace>
          </Card>
          <Card>
            <NSpace vertical>
              <NDataTable
                row-class-name='items'
                columns={this.columnsRef.columns}
                size='small'
                data={this.state.list}
                loading={this.state.loading}
                scrollX={this.columnsRef.tableWidth}
              />
              <NSpace justify='end'>
                <NPagination
                  v-model:page={this.state.page}
                  v-model:page-size={this.state.limit}
                  item-count={this.state.count}
                  show-size-picker
                  page-sizes={[10, 30, 50]}
                  show-quick-jumper
                  on-update:page={this.changePage}
                  on-update:page-size={this.changePageSize}
                />
              </NSpace>
            </NSpace>
          </Card>
        </NSpace>
      </>
    )
  }
})

// export default WorkPublishListTab
